package com.fin.zw.intelligentbot.controller;

import com.fin.zw.intelligentbot.annotation.CurrentUser;
import com.fin.zw.intelligentbot.entity.LineInfo;
import com.fin.zw.intelligentbot.model.request.CircuitRequest;
import com.fin.zw.intelligentbot.model.session.SessionModel;
import com.fin.zw.intelligentbot.service.LineInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@RestController
@RequestMapping("/line")
@Api(value = "线路管理",description = "线路管理")
public class LineInfoController {

    @Autowired
    private LineInfoService CircuitService;

    @GetMapping("/fetchPage")
    @ApiOperation(value = "查询所有的线路信息",notes = "查询所有的线路信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", dataType = "int", paramType = "query",
                    value = "页数 (0..N)"),
            @ApiImplicitParam(name = "size", dataType = "int", paramType = "query",
                    value = "每页大小."),
            @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query",
                    value = "依据什么排序: 属性名(,asc|desc). ")
    })
    public ResponseEntity<Page<LineInfo>> queryCircuitAll(Pageable pageable,
                                                          CircuitRequest request,
                                                          @ApiIgnore @CurrentUser SessionModel sessionModel){
        Page<LineInfo> page = CircuitService.querySceneInfoAll(pageable,request,sessionModel);
        return ResponseEntity.ok().body(page);
    }

    @GetMapping("/fetch")
    @ApiOperation(value = "查询所有的线路信息",notes = "查询所有的线路信息")
    public ResponseEntity<List<LineInfo>> getCircuitList(@ApiIgnore @CurrentUser SessionModel sessionModel){
        List<LineInfo> list = CircuitService.getCircuitList(sessionModel);
        return ResponseEntity.ok().body(list);
    }

    @PostMapping("/add")
    @ApiOperation(value = "添加线路信息",notes = "添加线路信息")
    public ResponseEntity<String> createCircuit(@RequestBody CircuitRequest request,
                                                  @ApiIgnore @CurrentUser SessionModel sessionModel){
        CircuitService.createCircuit(request,sessionModel);
        return ResponseEntity.ok().body("操作成功");
    }

    @RequestMapping(value = "/update",method = {RequestMethod.PUT,RequestMethod.PATCH})
    @ApiOperation(value = "更新线路信息",notes = "更新线路信息")
    public ResponseEntity<String> updateCircuit(@RequestBody CircuitRequest request,
                                                  @ApiIgnore @CurrentUser SessionModel sessionModel){
        CircuitService.updateCircuit(request,sessionModel);
        return ResponseEntity.ok().body("操作成功");
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "线路信息删除",notes = "线路信息删除")
    public ResponseEntity<String> deleteCircuit(@PathVariable String id,
                                                  @ApiIgnore @CurrentUser SessionModel sessionModel){
        CircuitService.deleteCircuit(id,sessionModel);
        return ResponseEntity.ok().body("操作成功");
    }
}
